<?php
import('TagLib');
/**
* 自定义标签
*/
Class TagLibHd extends TagLib{
 Protected $tags=array(
   'nav'=>array('attr'=>'limit,order','close'=>1),
   'new'=>array('attr'=>'limit,order','close'=>1),
   'frie'=>array('attr'=>'limit,order','close'=>1),
   'hot'=>array('attr'=>'limit,order','close'=>1),
   'list'=>array('attr'=>'limit,order','close'=>1)
 	);

	Public function _nav($attr,$content){
      $attr=$this->parseXmlAttr($attr);
      $str=<<<str
<?php
         \$cate=M('cate')->order("{$attr['order']}")->limit("{$attr['limit']}")->select();
         import("class.Category",APP_PATH);
         \$cate=Category::UnlimiteForLayer(\$cate);        
         foreach(\$cate as \$v): 
         extract(\$v);
         \$url='c_'.\$id;
?>
str;
       $str.=$content;
       $str.='<?php  endforeach ?>';
       return $str;
   }

   Public function _new($attr,$content){
    $attr=$this->parseXmlAttr($attr);
    $limit=$attr['limit'];
    $str='<?php ';
    $str.='$blog_new=M("blog")->limit('.$limit.')->order("time DESC")->select();';
    $str.='foreach($blog_new as $blog_new_v):';
    $str.='extract($blog_new_v);';
    $str.='$url=U("/".$id); ?>';
    $str.=$content;
    $str.='<?php endforeach; ?>';
      return $str;
   }	

   Public function _frie($attr,$content){
      $attr=$this->parseXmlAttr($attr);
      $limit=$attr['limit'];
      $str='<?php ';
      $str.='$blog_hot=M("blog")->limit('.$attr['limit'].')->order("click DESC")->select();';
      $str.='foreach($blog_hot as $blog_hot_v):;';
      $str.='extract($blog_hot_v);';
      $str.='$url=U("/".$id); ?>';
      $str.=$content;
      $str.='<?php endforeach; ?>';
      return $str;
   }

   public function _hot($attr,$content){
      $attr=$this->parseXmlAttr($attr);
      $str='<?php ';
      $str.='$blog=M("blog")->limit("'.$attr['limit'].'")->order("click DESC")->select();';
      $str.='foreach ($blog as $val): ;';
      $str.='extract($val);';
      $str.='$url=U("/".$id); ?>';
      $str.=$content;
      $str.='<?php endforeach ; ?>';
      return $str;
   }

   public function _list($attr,$content){
      $attr=$this->parseXmlAttr($attr);
      $str='<?php ';
      $str.='$blog=M("blog")->limit("'.$attr['limit'].'")->order("click DESC")->select();';
      $str.='foreach ($blog as $val): ;';
      $str.='extract($val);';
      $str.='$url=U("/".$id); ?>';
      $str.=$content;
      $str.='<?php endforeach ; ?>';
      return $str;
   }
}


?>
